#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    //实例化checkbox
    checkBox01=new QCheckBox(this);
    checkBox02=new QCheckBox(this);
    checkBox03=new QCheckBox(this);
    //实例label控件显示
    label=new QLabel(this);
    //控件位置
    checkBox01->setGeometry(QRect(50,50,50,50));
    checkBox02->setGeometry(QRect(100,50,50,50));
    checkBox03->setGeometry(QRect(150,50,50,50));
    label->setGeometry(QRect(50,100,200,30));
    //控件值

    checkBox01->setText("数学");
    checkBox02->setText("语文");
    checkBox03->setText("地理");
    //checkbxo控件点击事件
    connect(
                checkBox01,SIGNAL(clicked(bool)),
                this,
                SLOT(checkchange())
            );
    connect(
            checkBox02,
            SIGNAL(clicked(bool)),
            this,
            SLOT(checkChange())
            );
    connect(checkBox03,
            SIGNAL(clicked(bool)),
            this,
            SLOT(checkChange())
                );
}
//定义接收变量
QString str;
void MainWindow::checkChange()
{
    if(sender()==checkBox01)
    {//判断是否被选中
        if(checkBox01->checkState()==Qt::Checked)
        {
            str+="数学";
        }else{
            str=str.replace(QString("数学"),QString(""));
        }
    }else if(sender()==checkBox02)
    {
        if(checkBox02->checkState()==Qt::Checked)
        {
            str+="语文";
        }else{
            str=str.replace(QString("语文"),QString(""));
        }
    }else if(sender() ==checkBox03)
    {
        if(checkBox03->checkState()==Qt::Checked)
        {
            str+="地理";
        }else
        {
            str=str.replace(QString("地理"),QString(""));
        }
    }//绑定值
    label->setText(str);
}
MainWindow::~MainWindow()
{
    delete ui;
}
